{	Problem: http://codeforces.ru/problemset/problem/92/A
	Verdict: Accepted
}
var
    n,m,i:longint;

begin
read(n,m);
i:=1;
while m>=i do begin
  dec(m,i);
    i:=i mod n+1;
end;
write(m);
end.